﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using CE.User;

public partial class personal_accident_UserMessage : System.Web.UI.Page
{
    protected string _header;
    protected string _body;
    protected string _headerMsg;
    protected string _bodyMsg;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string ProviderId = "0";
            if (Request.QueryString["pcid"] != null)
            {
                ProviderId = Decode(Request.QueryString["pcid"]).ToString();
                if (ProviderId == "23")
                {
                    GetMessage(400, "PA", 23300);
                    _headerMsg = string.Format(_header);
                    _bodyMsg = string.Format(_body);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;
                    
                    //lblMessageHeader.Text = "Thank you for completing the form. Your proposal has been submitted to HSBC Insurance.";
                    //lblMessageBody.Text = "HSBC Insurance will send you an email confirmation within one working day from today's date if your proposal is accepted.";
                }
                else if (ProviderId == "29")
                {
                    GetMessage(400, "PA", 29300);
                    _headerMsg = string.Format(_header);
                    _bodyMsg = string.Format(_body);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;
                    
                    //lblMessageHeader.Text = "Thank you for completing the form. Your proposal has been submitted to Liberty Insurance.";
                    //lblMessageBody.Text = "Liberty Insurance will send you an email confirmation within one working day from today's date if your proposal is accepted";
                }
                else if (ProviderId == "30")
                {
                    GetMessage(400, "PA", 30300);
                    _headerMsg = string.Format(_header);
                    _bodyMsg = string.Format(_body);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;
                    
                    //lblMessageHeader.Text = "Thank you for completing the form. Your proposal has been submitted to Etiqa Insurance.";
                    //lblMessageBody.Text = "Etiqa Insurance will send you an email confirmation within one working day from today's date if your proposal is accepted";
                }
                else if (ProviderId == "34")
                {
                    GetMessage(400, "PA", 34300);
                    _headerMsg = string.Format(_header);
                    _bodyMsg = string.Format(_body);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;

                    //lblMessageHeader.Text = "Thank you for completing the form. Your proposal has been submitted to Etiqa Insurance.";
                    //lblMessageBody.Text = "Etiqa Insurance will send you an email confirmation within one working day from today's date if your proposal is accepted";
                }

                else if (ProviderId == "35")
                {
                    GetMessage(400, "PA", 35300);
                    _headerMsg = string.Format(_header);
                    _bodyMsg = string.Format(_body);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;

                  
                }
            }
            else
            {
                Response.Redirect("~/");
                //Response.Redirect("~/Home.aspx");
            }
            CE.Global.General.ClearAllSession(this.Page, "ALL");
        }
    }

    private void GetMessage(Int32 UserTypeId, string MessageType, Int32 ErrorCode)
    {
        MessageDB _messagedb = new MessageDB();
        DataTable _Message = new DataTable();
        _Message = _messagedb.GetMessage(UserTypeId, MessageType, ErrorCode);
        if (_Message != null && _Message.Rows.Count > 0)
        {
            _header = _Message.Rows[0]["Header"].ToString();
            _body = _Message.Rows[0]["Body"].ToString();
        }
        else
        {
            _header = "CompareXpress";
            _body = "No message found!";
        }
    }

    public string Decode(string sData)
    {
        try
        {
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(sData);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char);
            return result;
        }
        catch (Exception ex)
        {
            Response.Redirect("~/");
            //Response.Redirect("~/Home.aspx");
            string result = "";
            return result;
        }
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/");
    }

}
